#include <cstdio>

int map[ 1001 ][ 1001 ], f[ 1001 ][ 1001 ];

int main( )
{
    int t, i, j, k, n, m, p;
    scanf("%d", &t);
    for ( i = 1; i <= t; i++ )
    {
        scanf("%d%d", &n, &m);
        for ( j = 0; j < n; j++ )
            for ( k = 0; k < m; k++ )
                scanf("%d", &map[ j ][ k ]);
        f[ 0 ][ 0 ] = map[ 0 ][ 0 ];
        for ( j = 0; j < n; j++ )
            for ( k = 0; k < m; k++ )
            {
                if ( j == 0 && k == 0 )
                    continue;
                p = -0xfffffff;
                if ( j != 0 )
                    if ( p < f[ j - 1 ][ k ] )
                        p = f[ j - 1 ][ k ];
                if ( k != 0 )
                    if ( p < f[ j ][ k - 1 ] )
                        p = f[ j ][ k - 1 ];
                if ( j != 0 && k != 0 )
                    if ( p < f[ j - 1 ][ k - 1 ] )
                        p = f[ j - 1 ][ k - 1 ];
                f[ j ][ k ] = p + map[ j ][ k ];
            }
        printf("Scenario #%d:\n%d\n\n", i, f[ n - 1 ][ m - 1 ]);
    }
    return 0;
}
